<template>
  <div class="generate">
    <el-form @submit.prevent="handleGenerate">
      <el-form-item label="提示词">
        <el-input
          v-model="prompt"
          type="textarea"
          :rows="4"
          placeholder="请输入图片生成提示词"
        />
      </el-form-item>
      
      <el-form-item>
        <el-button type="primary" :loading="loading" @click="handleGenerate">
          生成图片
        </el-button>
      </el-form-item>
    </el-form>

    <div v-if="generatedImage" class="result">
      <img :src="generatedImage" alt="Generated image" />
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useImageStore } from '../stores/image'

const imageStore = useImageStore()
const prompt = ref('')
const generatedImage = ref('')
const loading = ref(false)

const handleGenerate = async () => {
  if (!prompt.value) return
  
  loading.value = true
  try {
    const result = await imageStore.generateImage(prompt.value, {})
    generatedImage.value = result.imageUrl
  } catch (error) {
    console.error('Generation failed:', error)
  } finally {
    loading.value = false
  }
}
</script>

<style scoped>
.generate {
  max-width: 800px;
  margin: 0 auto;
  padding: 24px;
}

.result {
  margin-top: 24px;
  
  img {
    width: 100%;
    border-radius: 8px;
  }
}
</style> 